package imageintegration

import (
	"fmt"
	"testing"

	"github.com/stackrox/rox/generated/storage"
	"github.com/stretchr/testify/assert"
)

func TestValidForSync(t *testing.T) {
	catsWithReg := []storage.ImageIntegrationCategory{storage.ImageIntegrationCategory_REGISTRY}
	catsWithoutReg := []storage.ImageIntegrationCategory{storage.ImageIntegrationCategory_SCANNER}
	catsMultiWithReg := []storage.ImageIntegrationCategory{storage.ImageIntegrationCategory_SCANNER, storage.ImageIntegrationCategory_REGISTRY}

	tt := []struct {
		ii       *storage.ImageIntegration
		expected bool
	}{
		{nil, false},
		{&storage.ImageIntegration{Autogenerated: true}, false},
		{&storage.ImageIntegration{Autogenerated: true, Categories: catsWithoutReg}, false},
		{&storage.ImageIntegration{Autogenerated: true, Categories: catsWithReg}, false},
		{&storage.ImageIntegration{Autogenerated: true, Categories: catsMultiWithReg}, false},
		{&storage.ImageIntegration{Autogenerated: false, Categories: catsWithoutReg}, false},
		{&storage.ImageIntegration{Autogenerated: false, Categories: catsWithReg}, true},
		{&storage.ImageIntegration{Autogenerated: false, Categories: catsMultiWithReg}, true},
	}

	for i, test := range tt {
		t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
			actual := ValidForSync(test.ii)
			assert.Equal(t, test.expected, actual)
		})
	}
}
